#include <algorithm>
#include <iostream>
#include <vector>
#define LL long long
using namespace std;

const int kMaxV = 5e5 + 10;
const int kMaxN = 5e5 + 10;

LL sum[kMaxV], cnt[kMaxV];
int a[kMaxN];

void Insert(LL t[], int pos, int x) {
  if (pos == 0) {
    t[pos] += x;
    return;
  }
  for (; pos < kMaxV; pos += pos & (-pos)) {
    t[pos] += x;
  }
}

LL GetSum(LL t[], int pos) {
  LL ret = t[0];
  if (pos < 0) {
    return 0;
  }
  for (; pos > 0; pos -= pos & (-pos)) {
    ret += t[pos];
  }
  return ret;
}

LL Query(LL t[], int l, int r) {
  return GetSum(t, r) - GetSum(t, l - 1);
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    Insert(sum, a[i], a[i]);
    Insert(cnt, a[i], 1);
  }

  for (int i = 0; i < q; i++) {
    int c;

    cin >> c;
    if (c == 1) {
      int x, y;

      cin >> x >> y;
      Insert(sum, a[x], -a[x]);
      Insert(cnt, a[x], -1);
      a[x] = y;
      Insert(sum, a[x], a[x]);
      Insert(cnt, a[x], 1);
    } else {
      int l, r;

      cin >> l >> r;
      if (l >= r) {
        cout << (LL)n * l << "\n";
      } else {
        cout << Query(cnt, 0, l - 1) * l + Query(cnt, r + 1, kMaxV) * r + Query(sum, l, r) << "\n";
      }
    }
  }
  return 0;
}